<?php
// +----------------------------------------------------------------------
// | QbtCMS
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 千佰特 <http://www.qbt8.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use plugins\qbt_payment_management\service\PayService;

class PayController extends HomeBaseController
{
    public function index()
    {
        return $this->fetch(':index');
    }

    //支付
    public function jspay(){
        $pay = new PayService();
        $pay_type = $_GET['pay_type'];
        $wxpay_type = [1=>'JSAPI',3=>'MWEB',5=>'NATIVE']; //微信支付方式
        $alipay_type = [2=>'wapPay',4=>'pagePay']; //支付宝支付方式
        //微信支付
        if (!empty($wxpay_type[$pay_type])){
            if ($wxpay_type[$pay_type]=='JSAPI'){
                // JSAPI支付必传参数
                $data['openid'] = 'objCojr10uG6cekGN3XJVVYw-doU';
            }
            if ($wxpay_type[$pay_type]=='NATIVE'){
                // NATIVE支付必传参数
                $data['product_id'] = 'Atest'.time().rand(100,999);
            }
            $data['order'] = 'Btest'.time().rand(100,999);
            $data['money'] = $_GET['money'];
            $data['body'] = '测试';
            $data['Trade_type'] = $wxpay_type[$pay_type];
            $paytype = 'WxPayController';
        }
        //支付宝支付
        if (!empty($alipay_type[$pay_type])){
            $data['order'] = 'test'.time().rand(100,999);
            $data['subject'] = 'subject';
            $data['money'] = $_GET['money'];
            $data['body'] = 'test';
            $data['pay_type'] = $alipay_type[$pay_type];
            $paytype = 'AliPayController';
        }
        $json = $pay->pay($paytype,$data);
        echo $json;
    }

    //支付页面
    public function pay(){
        return $this->fetch(':pay');
    }
}
